package cn.inst.user.contrller;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.inst.common.SecurityUntils;
import cn.inst.user.dao.UserMapper;
import cn.inst.user.domain.User;
import cn.inst.user.domain.UserExample;
import cn.inst.user.service.CheckUserServiceImp;
@Controller
@RequestMapping("test")
public class Ceshi {
	
	
	@Autowired
	private UserMapper userMapper;
	@Autowired
	private CheckUserServiceImp checkUserServiceImp;
	@RequestMapping("user0")
	public String user0(){
		System.out.println("进入");
		return "test";
		
	}
	@RequestMapping("user1")
	public String user1(User user) throws NoSuchAlgorithmException, UnsupportedEncodingException{
		System.out.println(user);
		String password=SecurityUntils.MD5Password(user.getPassword());
		user.setPassword(password);
		userMapper.insertSelective(user);
		return "test";
		
	}
	/**
	 * 测试MD5加密用的用的
	 * @throws UnsupportedEncodingException 
	 * @throws NoSuchAlgorithmException 
	 */
	public void MyTest1() throws NoSuchAlgorithmException, UnsupportedEncodingException{
		String password = SecurityUntils.MD5Password("yyj");
		System.out.println(password);
	}
	/**
	 * 测试MD5加密用的用的
	 * @throws UnsupportedEncodingException 
	 * @throws NoSuchAlgorithmException 
	 */
	public void MyTest3() throws NoSuchAlgorithmException, UnsupportedEncodingException{
		User user=new User();
		user.setUsername("yyj5");
		String password=SecurityUntils.MD5Password("yyj");
		user.setPassword(password);
		UserExample uExample=new UserExample();
		uExample.createCriteria().andUsernameEqualTo(user.getUsername()).andPasswordEqualTo(user.getPassword());
		List<User> list = userMapper.selectByExample(uExample);

		System.out.println(list.get(0));
	}
}
